<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<form class="layui-form layuimini-form" lay-filter="edit-form">
    <input name=id value="" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label required">用户名</label>
        <div class="layui-input-block">
            <input type="text" name="username" autocomplete="off" lay-verify="required" lay-reqtext="用户名不能为空" placeholder="请输入用户名" value="" class="layui-input">
            <tip>填写自己管理账号的名称。</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序值</label>
        <div class="layui-input-block">
            <input type="number" name="sort" autocomplete="off" placeholder="请输入排序值" value="0" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">昵称</label>
        <div class="layui-input-block">
            <input type="text" name="nickName" autocomplete="off" placeholder="请输入昵称" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">密码</label>
        <div class="layui-input-block">
            <input type="text" name="password" autocomplete="off" lay-verify="required" lay-reqtext="密码不能为空" placeholder="请输入密码" value="" class="layui-input">
            <tip>填写自己的密码。</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">确认密码</label>
        <div class="layui-input-block">
            <input type="text" name="repassword" autocomplete="off" lay-verify="required" lay-reqtext="确认密码不能为空" placeholder="请再次输入密码" value="" class="layui-input">
            <tip>填写自己的密码。</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">手机</label>
        <div class="layui-input-block">
            <input type="number" name="phoneNum" autocomplete="off" lay-verify="required" lay-reqtext="手机不能为空" placeholder="请输入手机" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-block">
            <input type="email" name="email" autocomplete="off" placeholder="请输入邮箱" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注信息</label>
        <div class="layui-input-block">
            <textarea name="remarks" autocomplete="off" class="layui-textarea" placeholder="请输入备注信息"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button id="saveBtn" class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">保存</button>
            <button type="reset" class="layui-btn layui-btn-danger">重置</button>
            <input type="button" class="layui-btn layui-btn-primary goback" value="返回"/>
        </div>
    </div>
</form>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../../js/lay-config.js?v=2.0.0" charset="utf-8"></script>
<script>
    function initView(obj){
        console.log(obj);
        var saveOneUrl = "/dicms/api/desktop/sys_user/save";
        layui.use(['form','common'], function () {
            var form = layui.form,
                layer = layui.layer,
                common = layui.common,
                $ = layui.$;

            //监听提交
            form.on('submit(saveBtn)', function (data) {
                data = data.field;
                if(data.nickName.length>10){
                    layer.msg('昵称太长!');
                    return false;
                }
                if (data.password !==data.repassword) {
                    layer.msg('两次密码输入不一样!');
                    return false;
                }
                $("#saveBtn").attr('disabled','disabled');
                $("#saveBtn").addClass("layui-btn-disabled");
                $.ajax({
                    url: saveOneUrl,
                    data: data,
                    type: 'post',
                    dataType: 'json',
                    success: function (res) {
                        console.log(res);
                        if (res.code !== 0) {
                            layer.msg(res.msg, function () {
                                $("#saveBtn").removeAttr('disabled');
                                $("#saveBtn").removeClass("layui-btn-disabled");
                            });
                        } else {
                            common.refreshAndClose();
                        }
                    },
                    error: function (res) {
                        console.log(res);
                        $("#saveBtn").removeAttr('disabled');
                        $("#saveBtn").removeClass("layui-btn-disabled");
                    }
                });
                return false;
            });

            $(".goback").click(function(e){
                common.closeIframe();
            });

        });
    }
</script>
</body>
</html>